<?php
	require_once(dirname(__FILE__) . "/../../config.php");
$database = Vars::$database; //database to create
$user = Vars::$dbuser;  //new user for access from php
$password = Vars::$dbpwd; //new user's password
$connection = mysql_connect('localhost', $user, $password);
if (!$connection) {
	die('Could not connect: ' . mysql_error());
}
@mysql_select_db($database, $connection) or die( "Unable to select database" . mysql_error());

if ( array_key_exists("q", $_GET) ) {
	$q = mysql_real_escape_string(strtolower($_GET["q"]));
} else {
	return;
}
if (!$q) return;

$sql = "SELECT name, icon, itemId FROM  items WHERE name LIKE  '%$q%' LIMIT 0 , 6";
$rsd = mysql_query($sql);
if ($rsd) {
	$return = array();
	//$return["totalResultsCount"] = mysql_num_rows($rsd);
	while ($rs = mysql_fetch_assoc($rsd)) {
		$return[] = $rs;
		//echo  "{$rs['name']}{$rs['icon']}{$rs['itemId']}";
	}
	echo json_encode($return);
}
?>